package com.example.controller;

import cn.hutool.json.JSONObject;
import com.example.common.Result;
import com.example.entity.*;
import com.example.entity.others.Test_Map_Question;
import com.example.entity.others.Test_User_Other;
import com.example.entity.others.User_Question;
import com.example.entity.others.User_Subject;
import com.example.service.StudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Resource
    StudentService studentService;

    //返回试卷标题,需要uid
    @PostMapping("/test/list")
    public Result testList(@RequestBody(required = false) User_Subject userSubject){
        return Result.success(studentService.testList(userSubject));
    }
    //用ai生成试卷题目，一整个test实体和uid
    @PostMapping("/create/ai")
    public Result createAi(@RequestBody Test_User_Other testUser){
        studentService.createAi(testUser);
        User_Subject userSubject = new User_Subject();
        userSubject.setSubject(testUser.getTest().getSubject());
        userSubject.setUid(testUser.getUser().getUid());
        return Result.success(studentService.testList(userSubject));
    }
    //人工组卷，返回数据库里面所有的这个学科的对应知识点的题目 test和user
    @PostMapping("/human/question")
    public Result humanQuestion(@RequestBody Test_User_Other testUser){
        return Result.success(studentService.humanQuestion(testUser));
    }
    //人工组卷，生成试卷 需要test的tid和questionMap和user
    @PostMapping("/create/human")
    public Result createHuman(@RequestBody Test_Map_Question testMapQuestion){
        studentService.createHuman(testMapQuestion);
        User_Subject userSubject = new User_Subject();
        userSubject.setSubject(testMapQuestion.getTest().getSubject());
        userSubject.setUid(testMapQuestion.getUser().getUid());
        return Result.success(studentService.testList(userSubject));
    }

    //人工组卷，生成试卷 需要test的tid和questionMap和user
    @PostMapping("/create/human/test")
    public Result createHumanTest(@RequestBody Test_User_Other testUserOther){
        return Result.success(studentService.createHumanTest(testUserOther));
    }

    //返回选定试卷的所有内容 需要tid,uid
    @PostMapping("/question/all")
    public Result questionAll(@RequestBody JSONObject testUserOther){
        int tid = testUserOther.getInt("tid");
        int uid = testUserOther.getInt("uid");
        return Result.success(studentService.questionAll(tid,uid));
    }
    //重置用户的做题
    @PostMapping("/question/reset")
    public Result questionReset(@RequestBody JSONObject testUserOther){
        int tid = testUserOther.getInt("tid");
        int uid = testUserOther.getInt("uid");
        studentService.questionReset(tid,uid);
        return Result.success(studentService.questionAll(tid,uid));
    }
    //用户保存答案（只保存不批改）
    @PostMapping("/do/homework")
    public Result doHomework(@RequestBody List<Question_Student> questionStudent){
        studentService.doHomework(questionStudent);
        return Result.success();
    }
    //用户提交试卷之后自动批改 需要问题的id,content,answer,uanswer
    @PostMapping("/correcting/ai")
    public Result correctingAi(@RequestBody List<User_Question> userQuestions){
        return Result.success(studentService.correctingAi(userQuestions));
    }
    //生成单一学科做题情况分析 需要sid（用户的id），subject
    @PostMapping("/create/analysis")
    public Result createAnalysisBySubject(@RequestBody Analysis_Student analysisStudent){
        studentService.createAnalysisBySubject(analysisStudent);
        return Result.success(studentService.getAnalysisAll(analysisStudent));
    }
    //返回指定学科的做题情况分析 需要subject和sid
    @PostMapping("/analysis/all")
    public Result analysisAll(@RequestBody Analysis_Student analysisStudent){
        return Result.success(studentService.getAnalysisAll(analysisStudent));
    }
    //返回所有的做题情况分析 需要subject和sid
    @PostMapping("/analysis/list")
    public Result analysisList(@RequestBody Analysis_Student analysisStudent){
        return Result.success(studentService.getAnalysisList(analysisStudent));
    }
    //删除指定试卷 需要uid，tid
    @PostMapping("/test/delete")
    public Result testDelete(@RequestBody Test_User testUser){
        return Result.success(studentService.testDelete(testUser));
    }
    //返回指定分析的内容
    @PostMapping("/get/content")
    public Result getAnalysisContent(@RequestBody Analysis_Student analysisStudent){
        return Result.success(studentService.getAnalysis(analysisStudent));
    }
    //删除指定分析
    @PostMapping("/delete/content")
    public Result DeleteAnalysisContent(@RequestBody Analysis_Student analysisStudent){
        return Result.success(studentService.deleteAnalysis(analysisStudent));
    }
    //加入班级 需要cid,sid,
    @PostMapping("/join/class")
    public Result joinClass(@RequestBody Class_Student classStudent){
        return Result.success(studentService.joinClass(classStudent));
    }
    //退出班级 需要cid,sid,
    @PostMapping("/cancel/class")
    public Result cancelClass(@RequestBody Class_Student classStudent){
        return Result.success(studentService.cancelClass(classStudent));
    }
    //返回班级列表
    @PostMapping("/list/class")
    public Result listClass(@RequestBody Class_Student classStudent){
        return Result.success(studentService.listClass(classStudent));
    }
    //返回家长列表
    @PostMapping("/list/parent")
    public Result listParent(@RequestBody Parent_Student parentStudent){
        return Result.success(studentService.listParent(parentStudent));
    }
    //绑定家长
    @PostMapping("/bind/parent")
    public Result bindParent(@RequestBody Parent_Student parentStudent){
        studentService.bindParent(parentStudent);
        return Result.success(studentService.listParent(parentStudent));
    }
    //解绑家长
    @PostMapping("/cancel/parent")
    public Result cancelParent(@RequestBody Parent_Student parentStudent){
        studentService.cancelParent(parentStudent);
        return Result.success();
    }
}
